package com.admxj.mybatis.demo.plugin;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;
import org.testcontainers.shaded.org.apache.commons.lang.builder.ReflectionToStringBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * @author admxj
 * @version Id: Demo, v 0.1 2020/6/5 12:23 上午 admxj Exp $
 */
public class Demo {

  private SqlSessionFactory sessionFactory;

  String url;
  String user;
  String password;

  @Before
  public void before() {
    try (Reader reader = Resources.getResourceAsReader("com/admxj/mybatis/demo/plugin/mybatis-config.xml")) {
      sessionFactory = new SqlSessionFactoryBuilder().build(reader);
    } catch (IOException throwables) {
      throwables.printStackTrace();
    }
  }


  @Test
  public void testPlugin() {
    SqlSession sqlSession = sessionFactory.openSession();

    Object o = sqlSession.selectOne("com.admxj.mybatis.demo.plugin.BookMapper.findById", 20);

    System.out.println(ReflectionToStringBuilder.toString(o));


  }

  @Test
  public void testQueryAll() {
    SqlSession sqlSession = sessionFactory.openSession();

    Object o = sqlSession.selectOne("com.admxj.mybatis.demo.plugin.BookMapper.queryAll");

    System.out.println(ReflectionToStringBuilder.toString(o));


  }


}
